import axios from 'axios';
import { setupInterceptor } from './interceptors.js';

function createAxios(option = {}, hasInterceptor = true) {
  const defBaseURL = window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API || import.meta.env.VITE_APP_GLOB_BASE_API;
  const defaultOptions = Object.assign(
    {
      timeout: 120000,
      baseURL: defBaseURL,
    },
    option,
  );
  const service = axios.create(defaultOptions);
  hasInterceptor && setupInterceptor(service);
  return service;
}

export const defaultAxios = createAxios(null);

export const fileAxios = createAxios(null, false);
